#include "volumelimiterwidget.h"
#include "ui_volumelimiterwidget.h"

#include <QVBoxLayout>
#include <QDebug>

VolumeLimiterWidget::VolumeLimiterWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::VolumeLimiterWidget)
{
    ui->setupUi(this);
    initUI();
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(showWidget()));
}

VolumeLimiterWidget::~VolumeLimiterWidget()
{
    delete ui;
    delete vSlider;
}
void VolumeLimiterWidget::initUI()
{
  //  mainLayout = new QHBoxLayout;
    vSlider = new VolumeSlider;
    vSlider->setWindowFlags(Qt::FramelessWindowHint);
   // mainLayout->addWidget(ui->pushButton);
    //setLayout(mainLayout);
    connect(vSlider,SIGNAL(focusOut()),this,SLOT(sliderHide()));

}
void VolumeLimiterWidget::showWidget()
{
    if (vSlider->isHidden()) {
        QPoint p(0,0);
        int x = mapToGlobal(p).x();
        int y = mapToGlobal(p).y();
        vSlider->resize(ui->pushButton->width()/2,120);
        vSlider->move(x+ui->pushButton->width()/4,y-vSlider->height()+10);
        vSlider->show();
        vSlider->setFocus();
        return;
    }
    else {
        vSlider->hide();
        return;
    }
}
void VolumeLimiterWidget::sliderHide()
{
    if (!vSlider->isHidden()) {
        vSlider->hide();
    }
}

